package com.data.data_base.service.Impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.data.data_base.domain.Student;
import com.data.data_base.mapper.StudentMapper;
import com.data.data_base.service.StudentService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Classname: StudentServiceImpl
 * @Description: service接口实现类
 * @Date: 2021/5/31
 * @Author: huwei
 */
@Service
@AllArgsConstructor
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    private final StudentMapper studentMapper;

    /**
     * 使用@DS表示数据源和yml文件中配的名称一致
     *
     */
    @Override
    @DS("master")
    public Integer saveMasterStudent(Student student) {
        return studentMapper.insert(student);
    }

    @Override
    @DS("slave")
    public Integer saveSalveStudent(Student student) {
        return studentMapper.insert(student);
    }

    @Override
    public IPage<Student> selectList(Integer pageNum, Integer pageCount) {
        Page<Student> page = new Page<>(pageNum, pageCount);
        return studentMapper.selectPage(page, null);
    }
}
